<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/22
 * Time: 21:05
 */
class Comments extends MY_Admin_Controller
{
    function __construct(){
        parent::__construct();
        $this->load->model('Comment_model');
        $this->assign('index_channel','contents');
    }
    function index(){
        $page = $this->input->get('page');
        $page = $page > 0? $page: 1;
        $order_id = $this->input->get('order_id');
        $user_id = $this->input->get('user_id');
        $activity_id = $this->input->get('activity_id');
        $condition['is_del'] = $this->input->get('is_del')>0?1:0;
        if($order_id){
            $condition['order_id']=$order_id;
        }
        if($user_id){
            $condition['user_id']=$user_id;
        }
        if($activity_id){
            $condition['activity_id']=$activity_id;
        }
        $base_url = url_query($condition, '/m-admin/comment/index');

        $pagination = $this->Comment_model->pagination($base_url, $page, $condition, 'id desc');
        $this->session->set_userdata(
            'back_list_page',
            $this->get_self_url()
        );
        $this->assign('pagination', $pagination);
        $this->display();
    }

    function del(){
        $comment_id = intval(trim($this->input->post('id')));
        if($comment_id<1){
            $this->json_response(false);
        }
        $comment = $this->Comment_model->soft_delete($comment_id);
        if($comment){
            $this->json_response(true);
        }
        $this->json_response(false);
    }
}